package leetcode.L46;

import java.util.ArrayList;
import java.util.List;

class Solution {
    //标记数组
    int[] flag;
    List<List<Integer>> list=new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        if (nums == null || nums.length == 0) {
            return list;
        }
        flag = new int[nums.length];
        domin(nums, new ArrayList<>());
        return list;
    }

    public void domin(int[] nums, List<Integer> dominList) {
        if (dominList.size() == nums.length) {
            list.add(new ArrayList<>(dominList));
            return;
        }
        for (int i = 0; i < flag.length; i++) {
            if (flag[i]==0) {
                dominList.add(nums[i]);
                flag[i]=1;
                domin(nums, dominList);
                flag[i]=0;
                dominList.remove(dominList.size() - 1);
            }
        }
    }
}